﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace Gmantis.Controls.Chart
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    public class NullableChartTypeConverter : TypeConverter
    {
        // Methods
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return (((sourceType != typeof(ChartType)) && (sourceType != typeof(string))) || true);
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if ((value is ChartType) || (value == null))
            {
                return (ChartType?)value;
            }
            string str = value as string;
            if (!string.IsNullOrEmpty(str))
            {
                return Enum.Parse(typeof(ChartType), str, true);
            }
            return base.ConvertFrom(context, culture, value);
        }
    }
}
